const { fnLoadingByOra, fetchReopLists, getTagLists, downDir, copyTempToLocalhost } = require('./utils/common');
const inquirer = require('inquirer');


module.exports = async (projectName) => {
    let repos = await fnLoadingByOra(fetchReopLists, '正在链接你的仓库...')();
    repos = repos.map((item) => item.name);
    //   console.log(repos);
    // console.log(`此处是文件${projectName}`);
    const { repo } = await inquirer.prompt([
        {
            type: 'list',
            name:'repo',
            message:'请选择一个你要创建的项目',
            choices: repos
        }
    ])

    let tags = await fnLoadingByOra(getTagLists, `正在链接你的选择的仓库${repo}的版本号...`)(repo);
    tags = tags.map((item) => item.name);
    const { tag } = await inquirer.prompt([
        {
            type: 'list',
            name: 'tag',
            message:'请选择一个该项目的版本下载',
            choices: tags
        }
    ])
    // console.log(`仓库 ${repo}的版本信息列表：${tag}`);

    // 下载项目到临时文件夹 target: C:\Users\a\.myTemplate
    const target = await fnLoadingByOra(downDir, '下载项目中...')(repo, tag);
    await copyTempToLocalhost(target, projectName);
};